package com.xxp.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxp.controller.request.BaseRequest;
import com.xxp.controller.request.CategoryRequest;
import com.xxp.entity.Category;
import com.xxp.mapper.CategoryMapper;
import com.xxp.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    /**
     * 分页查询
     */
    @Override
    public Object listByCondition(CategoryRequest baseRequest) {
        PageHelper.startPage(baseRequest.getPageNum(),baseRequest.getPageSize());
        //自关联查询
        List<Category> categories = categoryMapper.listByCondition(baseRequest);
        return new PageInfo<>(categories);
    }
    /**
     * 新增
     */
    @Override
    public void save(Category category) {
        Date date=new Date();
        category.setCreatetime(date);
        categoryMapper.save(category);
    }

    /**
     * 根据ID查询
     */
    @Override
    public Category getById(Integer id) {

        return categoryMapper.getById(id);
    }
    /**
     * 修改
     */
    @Override
    public void update(Category category) {
        Date date=new Date();
        category.setUpdatetime(date);
        categoryMapper.update(category);
    }
    /**
     * 删除
     */
    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }

    @Override
    public List<Category> list() {
        List<Category> list = categoryMapper.list();
        return list;
    }


}
